/**
 * Created by wangshaohua on 2018/1/30.
 */
var dialogWidth = null;
moduleCommon.service('DialogService', function (ngDialog, LanguageService, $timeout) {
    this.open = function (key, scope, preCloseCallbackFun, width) {
        if (scope instanceof Function) {
            preCloseCallbackFun = scope;
            scope = {};
        }
        var dialogPara = DialogState.map.get(key);
        if (dialogPara instanceof Object) {

            if(width){
                ngDialog.open({
                    template: dialogPara.template,
                    controller: dialogPara.controller,
                    scope: scope,
                    width: width,
                    preCloseCallback: preCloseCallbackFun,
                    closeByEscape: true,
                    trapFocus: false,
                    closeByDocument: false
                });
            }else{
                ngDialog.open({
                    template: dialogPara.template,
                    controller: dialogPara.controller,
                    scope: scope,
                    preCloseCallback: preCloseCallbackFun,
                    closeByEscape: true,
                    trapFocus: false,
                    closeByDocument: false
                });
            }
            // dialogWidth = width
            // $timeout(function () {
            //     if (dialogWidth) {
            //         if (isRealNum(dialogWidth)) {
            //             $('.ngdialog-content').css('width', dialogWidth + 'px');
            //         } else {
            //             $('.ngdialog-content').css('width', dialogWidth);
            //         }
            //     }
            //     dialogWidth = null;
            // }, 1000);

        } else {
            Alert.error(LanguageService.language('弹窗参数未配置!'));
        }
    };

    this.close = function () {
        ngDialog.closeAll();
    }
});